/* ---------------------------------------------------------------------------------------------
 *
 *            Capital Alliance Software Confidential Proprietary
 *            (c) Copyright CAS 201{x}, All Rights Reserved
 *                          www.pekall.com
 *
 * ----------------------------------------------------------------------------------------------
 */
package com.pekall.myDictionary.core;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

public class QQDictSource extends DictSource {

	private final static String prefixUrl = "http://dict.qq.com/dict?q=%s";

	private final static String mSource = "Dict.qq";

	public QQDictSource(Context context) {
		super(context);
	}

	@Override
	public String getUrl(String[] code) {
		String query = code[0];
		try {
			String url = String.format(prefixUrl, URLEncoder.encode(query,
					"utf-8"));
			return url;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Object parseContent(String content) {
		try {
			JSONObject objects = new JSONObject(content);
			JSONArray results = objects.getJSONArray("local");
			for (int i = results.length() - 1; i > 0; i--) {
				//JSONObject object = results.getJSONObject(i);
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
	@Override
	public String getSource() {
		return mSource;
	}

}
